package com.shenzhen.horselive.common.utils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

public class ImageUtils {

    public static Bitmap cropImage(Bitmap source, int x, int y, int width, int height) {
        if (source == null) return null;
        width = Math.min(width, source.getWidth());
        height = Math.min(height, source.getHeight());
        Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        Rect src = new Rect(x, y, width, height);
        Rect dest = new Rect(0, 0, width, height);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        canvas.drawBitmap(source, src, dest, paint);
        return result;
    }
}
